ReactJS Ultra For Beginners

📋 Rendering Lists in React

React makes it easy to display a collection of items using JavaScript’s map() function.


🔑 Key Points

  • Arrays → JSX
    Use array.map(item => <Component key={…} />) to transform each element into a React element.

  • key Prop
    A unique identifier for each item (helps React optimize updates).


🛠️ Example

import React from "react"; export default function TodoList() { const todos = [ { id: 1, text: "Learn React" }, { id: 2, text: "Build a project" }, { id: 3, text: "Deploy to production" }, ]; return ( <ul> {todos.map((todo) => ( <li key={todo.id}>{todo.text}</li> ))} </ul> ); }
  • todos.map(…) loops over each item.
  • For each todo, it returns an <li> with todo.text.
  • key={todo.id} gives React a stable way to track each element.

That’s it! You now know how to render lists in React using map(). 🎉